package com.mystyle.le.weekproject.asynctaks;

import android.content.Context;
import android.os.AsyncTask;
import android.widget.ImageView;
import android.widget.TextView;

import com.mystyle.le.weekproject.beans.HeadTitls;
import com.mystyle.le.weekproject.intentfactbackcall.MyCallBack;
import com.mystyle.le.weekproject.utils.DownData;
import com.mystyle.le.weekproject.utils.FileUtils;
import com.mystyle.le.weekproject.utils.ParseJson;
import com.squareup.picasso.Picasso;

import java.util.List;

/**资讯头条顶部滑动广告的下载任务
 * Created by le on 2016/10/10.
 */
public class HeadTitlesAsyncTaks extends AsyncTask<String,Void,List<HeadTitls>> {
   private MyCallBack.HeadBack headBack;
    private Context context;

    public HeadTitlesAsyncTaks(MyCallBack.HeadBack headBack, Context context) {
        this.headBack = headBack;
        this.context = context;
    }

    @Override
    protected List<HeadTitls> doInBackground(String... params) {
        boolean netWorkConn = DownData.isNetWorkConn(context);
        if (netWorkConn){
            String param = params[0];
            byte[] bytes = DownData.downData(param);
            if (bytes!=null&&bytes.length>0){
                String path = new String(bytes,0,bytes.length);
                return ParseJson.parseHeadJson(path);
            }
        }
       return null;
    }

    @Override
    protected void onPostExecute(List<HeadTitls> headTitlses) {
        super.onPostExecute(headTitlses);
        if (headTitlses!=null&&headTitlses.size()>0){
          headBack.sendBack(headTitlses);
        }
    }
}
